﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：武双 
    //
    // 文件名：BulidPaymentAdd.cs
    // 文件功能描述：结算管理：新增结算单
    // 创建标识：武双2009-05-12
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.Web;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;

namespace HZ.DrugTrade.Web.Hospitals.StorageManage
{
    public partial class PurchaseGoodsDetails : BasePage
    {
        //public PurchaseGoodsDetails()
        //{
        //    this.ModuleNo = Module.采购单管理.ToString();
        //}
        IBLL_Statistics iStatistics = Factory.BLL_Statistics();
        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        protected void Page_Load(object sender, EventArgs e)
        {
            IBLL_Hospital ih = Factory.BLL_Hospital();
            string hID = CurrentAccount.Account.Org.OrgID;
            Model.HospitalInfo hospital = ih.GetHospitalInfoByID(hID);
            if (hospital != null)
            {
                if (!HZ.DrugTrade.Web.Function.IsThreeLevel())//项目查询条件仅三级医院可见
                {
                    this.ddlProjectid.Visible = false;
                    this.lblProjectid.Visible = false;
                }
            }
            if (!IsPostBack)
            {
                //绑定所有项目
                //ProcurementProject procurementProject = new ProcurementProject();
                //procurementProject.ProcureStartTimeFrom = Convert.ToDateTime("1890-01-01");
                //procurementProject.ProcureStartTimeTo = Convert.ToDateTime("2099-12-31");
                //procurementProject.ProcureEndTimeFrom = Convert.ToDateTime("2000-01-01");
                //procurementProject.ProcureEndTimeTo = Convert.ToDateTime("2099-12-31");
                //int temp;
                //IList<ProcurementProject> projectList = ipb.GetProjectByWhere(procurementProject, 1, 0, out temp);
                //ddlProject.DataSource = projectList;
                //ddlProject.DataTextField = "ProjectName";
                //ddlProject.DataValueField = "ProjectID";
                //ddlProject.DataBind();
                //ListItem item = new ListItem();
                //item.Text = Constants.ALL_ITEM_TEXT;
                //item.Value = Constants.ALL_ITEM_VALUE;
                //ddlProject.Items.Insert(0, item);
                Binddata();
            }
        }

        protected void Binddata()
        {
            int totalrecord = 0;
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            Model.Query.Statistics_Hospital where = new HZ.DrugTrade.Model.Query.Statistics_Hospital();
            if (CurrentAccount.GetUser().UserID.Substring(0, 2).ToUpper().Equals("QS"))
            {
                where.CompanyId_SC = CurrentAccount.GetUser().Org.OrgID;
            }
            else if (CurrentAccount.GetUser().UserID.Substring(0, 2).ToUpper().Equals("QJ"))
            {
                where.CompanyId_TB = CurrentAccount.GetUser().Org.OrgID;
            }
            else
            {
                where.HospitalID = CurrentAccount.GetUser().Org.OrgID;
            }
            //where.CompanyName_TB = txtCompanyName_TB.Text.Trim();
            where.CompanyName_SC = txtCompanyName_SC.Text.Trim();
            where.Material = txtMaterial.Text.Trim();
            where.PinyinCode = this.txtpinyincode.Text.Trim();
            where.Outlookc = txtOutlookc.Text.Trim();
            //where.GoodsID=txtGoodsid.Text.Trim();
            where.GoodsName = txtGoodsName.Text.Trim();
            if (!string.IsNullOrEmpty(txtPlanTimeFrom.Text.Trim()))
            {
                where.PlanTimeFrom = Convert.ToDateTime(txtPlanTimeFrom.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtPlanTimeTo.Text.Trim()))
            {
                where.PlanTimeTo = Convert.ToDateTime(txtPlanTimeTo.Text.Trim());
            }
            //where.ProjectID = this.ddlProjectid.SelectedValue;
            if (this.ddlProjectid.Visible != false)
            {
                where.ProjectID = this.ddlProjectid.SelectedValue;
            }
            else
            {
                where.ProjectID = "0001";
            }
            where.SortFields = " GoodsName asc,Goodsid";
            IList<Model.View.Statistics_Hospital> lstStahosp = iStatistics.GetStatistics_Hospital(where, this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalrecord);
            gvwProduceCatalog.DataSource = lstStahosp;
            gvwProduceCatalog.DataBind();
            this.AspNetPager1.RecordCount = totalrecord;
        }



        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            Binddata();
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            Binddata();
        }
        protected void lbnSwitch_Click(object sender, EventArgs e)
        {
            if (lbnSwitch.CommandArgument == "simple")
            {
                ltlAdvance.Text = "";
                lbnSwitch.CommandArgument = "advance";
                lbnSwitch.Text = "简单查询";
            }
            else
            {
                ltlAdvance.Text = "<tbody id='advance' style='display:none'>";
                lbnSwitch.CommandArgument = "simple";
                lbnSwitch.Text = "高级查询";

                ////清空数据

                txtGoodsName.Text = "";
                //txtCompanyName_TB.Text = "";
                txtCompanyName_SC.Text = "";
            }
        }
        /// <summary>
        /// 导出Excel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            int totalrecord = 0;
            Model.Query.Statistics_Hospital where = new HZ.DrugTrade.Model.Query.Statistics_Hospital();
            if (CurrentAccount.GetUser().UserID.Substring(0, 2).ToUpper().Equals("QS"))
            {
                where.CompanyId_SC = CurrentAccount.GetUser().Org.OrgID;
            }
            else if (CurrentAccount.GetUser().UserID.Substring(0, 2).ToUpper().Equals("QJ"))
            {
                where.CompanyId_TB = CurrentAccount.GetUser().Org.OrgID;
            }
            else
            {
                where.HospitalID = CurrentAccount.GetUser().Org.OrgID;
            }
            //where.CompanyName_TB = txtCompanyName_TB.Text.Trim();
            where.CompanyName_SC = txtCompanyName_SC.Text.Trim();
            where.Material = txtMaterial.Text.Trim();
            where.Outlookc = txtOutlookc.Text.Trim();
            where.GoodsName = txtGoodsName.Text.Trim();
            //where.ProjectID = this.ddlProjectid.SelectedValue;
            if (this.ddlProjectid.Visible != false)
            {
                where.ProjectID = this.ddlProjectid.SelectedValue;
            }
            else
            {
                where.ProjectID = "0001";
            }
            //zzr 2010-03-04 采购时间
            if (!string.IsNullOrEmpty(txtPlanTimeFrom.Text.Trim()))
            {
                where.PlanTimeFrom = Convert.ToDateTime(txtPlanTimeFrom.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtPlanTimeTo.Text.Trim()))
            {
                where.PlanTimeTo = Convert.ToDateTime(txtPlanTimeTo.Text.Trim());
            }
            where.SortFields = " Goodsid";
            IList<Model.View.Statistics_Hospital> lstStahosp = iStatistics.GetStatistics_Hospital(where, 1, 0, out totalrecord);
            DataTable dt = HZ.Data.ModelConvert.GetDataTableFromModel(lstStahosp);
            HZ.Excel.ExcelHelper.ExportDataForWeb(dt, gvwProduceCatalog);
        }
    }
}
